package com.ssm.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ssm.entity.HouseUser;
import com.ssm.service.HouseUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author jie_ge
 * @Date 2022/4/19
 */
@Controller
@RequestMapping("/houseUser")
public class HouseUserController  {
    @Reference
    private HouseUserService houseUserService;

    /**
     * 添加
     * @param map
     * @param houseId
     * @return
     */
    @GetMapping("/create")
    public String create(Map map, @RequestParam("houseId") Long houseId) {
        map.put("houseId",houseId);
        return "houseUser/create";
    }

    /**
     * 保存添加
     * @param houseUser
     * @return
     */
    @PostMapping("/save")
    public String save(HouseUser houseUser) {
        houseUserService.insert(houseUser);
        return "common/successPage";
    }

    /**
     * 修改
     * @param id
     * @param map
     * @return
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id,Map map) {
        HouseUser houseUser = houseUserService.getById(id);
        map.put("houseUser",houseUser);
        return "houseUser/edit";
    }

    /**
     * 保存修改
     * @param houseUser
     * @return
     */
    @PostMapping("/update")
    public String update(HouseUser houseUser) {
        houseUserService.update(houseUser);
        return "common/successPage";
    }

    /**
     * 删除
     * @param houseId
     * @param map
     * @return
     */
    @GetMapping("/delete/{houseId}/{id}")
    public String delete(@PathVariable("houseId") Long houseId,Map map,@PathVariable("id") Long id) {
        houseUserService.deleteById(id);
        return "redirect:/house/"+houseId;
    }
}
